package com.client.mapper;

import org.apache.ibatis.annotations.*;

import java.sql.Timestamp;

@Mapper
public interface MessageDao {

    //用来查询uuid是否重复
    @Select("select uuid from messagerecord where uuid = #{uuid}")
    String query(@Param("uuid") String uuid);

    //根据uid搜索设备标识
    @Select("select distinct identification from messagerecord where uid = #{uid} and myid=#{myid}")
    String queryByUID(@Param("uid") String uid,@Param("myid") String myid);

    //增加
    @Insert("insert into messagerecord values(null,#{identification},#{myid}, #{ip}, #{port}, #{uid}, " +
            "#{uuid}, #{isSend}, #{type},#{time})")
    void add(
            @Param("identification") String identification,
            @Param("myid") String myid,
            @Param("ip") String ip,
            @Param("port") int port,
            @Param("uid") String uid,
            @Param("uuid") String uuid,
            @Param("isSend") int isSend,
            @Param("type") String type,
            @Param("time") Timestamp date);

    //删除七天之前的数据
    @Delete("delete from messagerecord where time <= (NOW()-INTERVAL 7 day)")
    void delete();

}
